import java.io.*;

public class TestbufferReader {

    public static void main(String[] args) {
        BufferedReader br = null;
        BufferedWriter bw = null;
        try {
            br = new BufferedReader(new FileReader("src\\fin.txt"));
            bw = new BufferedWriter(new FileWriter("src\\fout.txt"));

            String str;
            int i = 1;
            while((str = br.readLine())!=null){
                bw.write(i + "," + str);
                bw.newLine();//换行
                i++;
            }
            bw.flush();//把缓冲区内容写到文件
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (bw != null) {
                try {
                    bw.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}